package com.wkh.datastructure.DeleteNode;

import com.wkh.datastructure.DeleteNode.ListNode ;

//根据值删除节点
public class demo1 {

    public static void main(String[] args) {
        ListNode node4 = new ListNode(null, 2);
        ListNode node3 = new ListNode(node4, 2);
        ListNode node2 = new ListNode(node3, 2);
        ListNode node1= new ListNode(node2, 2);
        ListNode head= new ListNode(node1, -1);
        ListNode newNode = delete(head,2);
    }
    public static ListNode delete(ListNode head,int value){
        ListNode p1 = head;
        ListNode p2 = head.next;
        while (p2 != null){
            if (p2.value == value){
                p2 = p2.next;
                p1.next = p2;
            }else{
                p1 = p1.next;
                p2 = p2.next;
            }
        }
        return head.next;
    }
}
